package com.test.mybatisDemo;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.InputStream;

/**
 * ${DESCRIPTION}
 *
 * @author muxiaoyu
 * @create 2017/06/28 13:12
 **/
public class MybatisDemo {
    public static void main(String[] args) throws Exception {
        String resource = "mybatis-config.xml";
        InputStream resourceAsStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        User user = sqlSession.selectOne("xiaoyu.selectUser", 7l);
        System.out.println(user);
    }

    @Test
    public void test1() throws Exception {
        String resource = "mybatis-config.xml";
        InputStream resourceAsStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        String tDate = "2017-06-";
        String tTimeStart = "08:35:07";
        String tTimeEnd = "17:35:07";
        for (int i = 10; i <= 30; i++) {
            //早上打卡模拟
            HrmScheduleSign hrmScheduleSign = new HrmScheduleSign();
            hrmScheduleSign.setSignDate(tDate + i);
            hrmScheduleSign.setSignTime(tTimeStart);
            hrmScheduleSign.setSignType(1);
            sqlSession.insert("HrmScheduleSign.insertHrmScheduleSign", hrmScheduleSign);
            //晚上打卡模拟
            HrmScheduleSign hrmScheduleSign1 = new HrmScheduleSign();
            hrmScheduleSign1.setSignDate(tDate + i);
            hrmScheduleSign1.setSignTime(tTimeEnd);
            hrmScheduleSign1.setSignType(2);
            sqlSession.insert("HrmScheduleSign.insertHrmScheduleSign", hrmScheduleSign1);
        }
        sqlSession.commit();
        // System.out.println(user);
    }
}
